package com.tencreat.mall.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.pt.MallPtBonusPool;
import com.tencreat.service.pt.IMallPtBonusPoolService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 奖金池Controller
 *
 * @author wangkai
 * @date 2021-11-30
 */
//@Api(tags="奖金池api")
@RestController
//RequestMapping("/system/pool")
public class MallPtBonusPoolController extends BaseController {
    //@Autowired
    private IMallPtBonusPoolService mallPtBonusPoolService;

    /**
     * 查询奖金池列表
     */
    @ApiOperation(value="查询奖金池列表")
    @PreAuthorize("@ss.hasPermi('system:pool:list')")
    @PostMapping("/list")
    public HttpResult<IPage<MallPtBonusPool>> list(@RequestBody  MallPtBonusPool mallPtBonusPool) {
        QueryWrapper<MallPtBonusPool> wrapper = Wrappers.query(mallPtBonusPool);
        Page<MallPtBonusPool> page =  new Page<>(mallPtBonusPool.getPageNum(), mallPtBonusPool.getPageSize());
        return HttpResult.ok(mallPtBonusPoolService.page(page, wrapper));
    }

    /**
     * 导出奖金池列表
     */
    @ApiOperation(value="导出奖金池列表")
    @PreAuthorize("@ss.hasPermi('system:pool:export')")
    @Log(title = "奖金池", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(MallPtBonusPool mallPtBonusPool) {
        List<MallPtBonusPool> list = mallPtBonusPoolService.selectMallPtBonusPoolList(mallPtBonusPool);
        ExcelUtil<MallPtBonusPool> util = new ExcelUtil<MallPtBonusPool>(MallPtBonusPool.class);
        return util.exportExcel(list, "pool");
    }

    /**
     * 获取奖金池详细信息
     */
    @ApiOperation(value="获取奖金池详细信息")
    @PreAuthorize("@ss.hasPermi('system:pool:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<MallPtBonusPool> getInfo(@RequestBody   ReqIdParam id) {
        return HttpResult.ok(mallPtBonusPoolService.selectMallPtBonusPoolById(id));
    }

    /**
     * 新增奖金池
     */
    @ApiOperation(value="新增奖金池")
    @PreAuthorize("@ss.hasPermi('system:pool:add')")
    @Log(title = "奖金池", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody  MallPtBonusPool mallPtBonusPool) {
        return to(mallPtBonusPoolService.insertMallPtBonusPool(mallPtBonusPool));
    }

    /**
     * 修改奖金池
     */
    @ApiOperation(value="修改奖金池")
    @PreAuthorize("@ss.hasPermi('system:pool:edit')")
    @Log(title = "奖金池", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody  MallPtBonusPool mallPtBonusPool) {
        return to(mallPtBonusPoolService.updateMallPtBonusPool(mallPtBonusPool));
    }

    /**
     * 删除奖金池
     */
    @ApiOperation(value="删除奖金池")
    @PreAuthorize("@ss.hasPermi('system:pool:remove')")
    @Log(title = "奖金池", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody  ReqIdsParam ids) {
        return to(mallPtBonusPoolService.deleteMallPtBonusPoolByIds(ids));
    }
}
